package cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistwlmq;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistwlmq.vo.DpWestListWlmqPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistwlmq.vo.DpWestListWlmqRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistwlmq.vo.DpWestListWlmqSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.dplist.DpWestListWlmqDO;
import cn.iocoder.yudao.module.erp.service.dpwest.DpWestListWlmqService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 乌鲁木齐西线清单")
@RestController
@RequestMapping("/erp/dp-west-list-wlmq")
@Validated
public class DpWestListWlmqController {

    @Resource
    private DpWestListWlmqService dpWestListWlmqService;

    @PostMapping("/create")
    @Operation(summary = "创建乌鲁木齐西线清单")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-wlmq:create')")
    public CommonResult<Long> createDpWestListWlmq(@Valid @RequestBody DpWestListWlmqSaveReqVO createReqVO) {
        return success(dpWestListWlmqService.createDpWestListWlmq(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新乌鲁木齐西线清单")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-wlmq:update')")
    public CommonResult<Boolean> updateDpWestListWlmq(@Valid @RequestBody DpWestListWlmqSaveReqVO updateReqVO) {
        dpWestListWlmqService.updateDpWestListWlmq(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除乌鲁木齐西线清单")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-wlmq:delete')")
    public CommonResult<Boolean> deleteDpWestListWlmq(@RequestParam("id") Long id) {
        dpWestListWlmqService.deleteDpWestListWlmq(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得乌鲁木齐西线清单")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-wlmq:query')")
    public CommonResult<DpWestListWlmqRespVO> getDpWestListWlmq(@RequestParam("id") Long id) {
        DpWestListWlmqDO dpWestListWlmq = dpWestListWlmqService.getDpWestListWlmq(id);
        return success(BeanUtils.toBean(dpWestListWlmq, DpWestListWlmqRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得乌鲁木齐西线清单分页")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-wlmq:query')")
    public CommonResult<PageResult<DpWestListWlmqRespVO>> getDpWestListWlmqPage(@Valid DpWestListWlmqPageReqVO pageReqVO) {
        PageResult<DpWestListWlmqDO> pageResult = dpWestListWlmqService.getDpWestListWlmqPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DpWestListWlmqRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出乌鲁木齐西线清单 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-wlmq:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDpWestListWlmqExcel(@Valid DpWestListWlmqPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DpWestListWlmqDO> list = dpWestListWlmqService.getDpWestListWlmqPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "乌鲁木齐西线清单.xls", "数据", DpWestListWlmqRespVO.class,
                        BeanUtils.toBean(list, DpWestListWlmqRespVO.class));
    }

}